﻿$('body').ready(
	function (){
		var arr;
		var str= '';
		var allobj = $("span[name='price_usd']");
		var exchange = $('#exchange').val();//alert(exchange);
		
		for(var i=0;i<allobj.length;i++){
			str = String(round( (allobj.eq(i).html() * 100)*exchange / 100 , 4 ) );
			//str = String((allobj.eq(i).html() * 100)*exchange / 100 );
			
			arr = str.split(".");
			
			str = moneyFormat(arr[0]);
			
			if(arr[1]!=null){
				str = str+'.'+arr[1];
			}
			allobj.eq(i).html(str);
			//allobj.eq(i).html(round(str,2));
		}
		
	}
); 


function   round(number,X)   { 
	//   rounds   number   to   X   decimal   places,   defaults   to   2 
	X   =   (!X   ?   2   :   X); 
	return   Math.round(number*Math.pow(10,X))/Math.pow(10,X); 
} 

function moneyFormat(str){
	if(str.length<=3){
		return str;
	}else{
		return moneyFormat(str.substr(0,str.length-3))+", "+(str.substr(str.length-3));
	}
}